package com.hzlh.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.web.http.CookieSerializer;

@Configuration
public class SpringSessionConfig {

    @Value("${spring.profiles.active}")
    private String profiles;

    public SpringSessionConfig() {
    }

    @Bean
    public CookieSerializer httpSessionIdResolver() {
        MyCookieSerializer cookieSerializer = new MyCookieSerializer();
        // 取消仅限同一站点设置
        cookieSerializer.setUseHttpOnlyCookie(false);
        cookieSerializer.setSameSite(null);
        if ("prod".equals(profiles)) {
            cookieSerializer.setUseSecureCookie(true);
            cookieSerializer.setSameSite("None");
        } else {
            cookieSerializer.setSameSite(null);
        }
        return cookieSerializer;
    }
}
